<template>
  <div class="contain">
    <p>时间：{{dateYear}}-{{dateWeek}}-{{dateDay}}</p>
  </div>
</template>

<script>
export default {
    name:"NowTime",
    data () {
    return {
      dateDay: null,
      dateYear: null,
      dateWeek: null,
      weekday: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
      timer:null
      };
    },
    created () {
      // 设置定时器，每秒更新时间
    this.timer =setInterval(() => {
        const date=this.$dayjs(new Date())
        this.dateDay = date.format('HH:mm:ss');
        this.dateYear = date.format('YYYY-MM-DD');
        this.dateWeek = date.format(this.weekday[date.day()]);
 
      }, 1000)
  },
  beforeDestroy(){
    if(this.timer){
      clearInterval(this.timer)
    }
  }
}
</script>

<style scoped>
.contain{
    height: 20px;
    border-bottom: 1px solid #E4E7ED;
}
p{
    line-height: 10px;
    margin-left: 20px;
    font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
}
</style>